namespace ScrumSprintMonitor.Wpf.Application
{
	#region #using Directives

	using System.Diagnostics.CodeAnalysis;
	using System.Windows;
	using System.Windows.Forms;

	using Design;

	using Implementation;

	using Infrastructure;
	using Infrastructure.Configuration;

	using Ninject.Core;
	using Ninject.Core.Behavior;

	using UI.Wpf;

	#endregion

	[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses",
		Justification = "The NinjectContainerAbstraction will create this class")]
	internal class NinjectAppDesignTimeModule : StandardModule
	{
		/// <summary>
		/// Loads the module into the kernel.
		/// </summary>
		public override void Load()
		{
			SetupDesignTimeBindings();
		}

		private void SetupDesignTimeBindings()
		{
			// TODO: Mock the following two concrete classes
			Bind<IConnectionProvider>().To<ConnectionProvider>().Using<SingletonBehavior>();
			Bind<IProcessTemplateAdapterProvider>().To<MefProcessTemplateAdapterProvider>().Using<SingletonBehavior>();
			Bind<ISprintConfiguration>().ToConstant(TestAssetLibrary.CreateSprintConfiguration());
			Bind<IPresentationConfiguration>().To<TestAssetLibrary.HardcodedPresentationConfiguration>().Using<SingletonBehavior>();

			var shellLayoutConfiguration = new ShellLayoutConfiguration(SystemInformation.MonitorCount > 1, !Bootstrapper.Debug, true, SprintMode.Sprinting);
			Bind<IShellLayoutConfiguration>().ToConstant(shellLayoutConfiguration);
		}
	}

	/// <summary>
	/// Provides a custom implementation of DesignerProperties.GetIsInDesignMode
	/// to work around an issue.
	/// </summary>
	internal static class StubDesignerProperties
	{
		/// <summary>
		/// Stores the computed InDesignMode value.
		/// </summary>
		private static bool? isInDesignMode;

		/// <summary>
		/// Returns whether the control is in design mode (running under Blend
		/// or Visual Studio).
		/// </summary>
		/// <param name="element">The element from which the property value is
		/// read.</param>
		/// <returns>True if in design mode.</returns>
		[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "element",
			Justification = "Matching declaration of System.ComponentModel.DesignerProperties.GetIsInDesignMode (which has a bug and is not reliable).")]
		public static bool GetIsInDesignMode(DependencyObject element)
		{
			if (!isInDesignMode.HasValue)
			{
				isInDesignMode = (null == System.Windows.Application.Current) || !(System.Windows.Application.Current is App);
			}
			return isInDesignMode.Value;
		}
	}
}